<% nickname ||= false %>
<% conversation_path = nickname ? decidim.profile_conversation_path(conversation, nickname:) : decidim.conversation_path(conversation) %>

<%= link_to conversation_path, id: "conversation-#{conversation.id}", class: "conversation__item" do %>
  <div class="conversation__item-avatar">
    <% if conversation.interlocutors(current_user).count == 1 %>
      <%= cell "decidim/author", present(conversation.interlocutors(current_user).first), layout: :avatar, skip_profile_link: true %>
    <% else %>
      <%= icon "group-line", class: "w-4 h-4 text-gray fill-current" %>
    <% end %>
  </div>

  <div class="conversation__item-snippet">
    <div class="conversation__item-snippet-title" data-interlocutors-list>
      <h2 class="h5 text-secondary">
        <%= conversation.interlocutors(current_user).last.name %>
      </h2>

      <% if conversation.interlocutors(current_user).count > 1 %>
        <div class="flex -space-x-2">
          <% conversation.interlocutors(current_user).each do |interlocutor| %>
            <span class="rounded-full border border-white inline-block w-6 h-6">
              <%= cell "decidim/author", present(interlocutor), layout: :avatar, skip_profile_link: true %>
            </span>
          <% end %>
        </div>
      <% end %>
    </div>

    <p class="conversation__item-snippet-message"><%= truncate conversation.last_message.body, length: 150 %></p>

    <div class="conversation__item-snippet-time">
      <%= t("decidim.user_conversations.index.time_ago", time: time_ago_in_words(Time.zone.parse(conversation.last_message.created_at.to_s))) %>
    </div>
  </div>

  <div class="conversation__item-unread">
    <% if conversation.unread_count(current_user).positive? %>
      <span><%= conversation.unread_count(current_user) %></span>
    <% end %>
  </div>
<% end %>
